﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QuickSSH.UI
{
    public partial class MainForm : Form
    {
        // 主要控件
        private TabControl tabControl;
        private MenuStrip menuStrip;
        private ToolStrip toolStrip;
        private StatusStrip statusStrip;
        private ListView sessionListView;
        public MainForm()
        {
            InitializeComponent();
            InitializeComponent2();
        }

        private void InitializeComponent2()
        {
            // 1. 主分割容器
            SplitContainer mainSplit = new SplitContainer
            {
                Orientation = Orientation.Horizontal,
                Dock = DockStyle.Fill,
                SplitterDistance = 150
            };

            // 2. 会话管理区 (上方)
            GroupBox sessionGroup = new GroupBox
            {
                Text = "会话管理",
                Dock = DockStyle.Fill
            };

            // 会话列表
            sessionListView = new ListView
            {
                View = View.Details,
                Columns = { "名称", "主机", "用户", "状态" },
                FullRowSelect = true,
                Dock = DockStyle.Fill
            };

            // 3. 终端操作区 (下方)
            tabControl = new TabControl
            {
                Dock = DockStyle.Fill,
                Appearance = TabAppearance.FlatButtons
            };

            // 组装界面
            sessionGroup.Controls.Add(sessionListView);
            mainSplit.Panel1.Controls.Add(sessionGroup);
            mainSplit.Panel2.Controls.Add(tabControl);
            this.Controls.Add(mainSplit);

            CreateMenu();
            CreateToolbar();
            CreateStatusBar();
        }

        private void CreateMenu()
        {
            menuStrip = new MenuStrip();

            // 文件菜单
            ToolStripMenuItem fileMenu = new ToolStripMenuItem("文件(&F)");
            fileMenu.DropDownItems.AddRange(new[] {
                new ToolStripMenuItem("新建会话(&N)"),
                new ToolStripMenuItem("保存会话(&S)"),
                new ToolStripMenuItem("退出(&X)")
            });

            // 编辑菜单
            ToolStripMenuItem editMenu = new ToolStripMenuItem("编辑(&E)");
            editMenu.DropDownItems.AddRange(new[] {
                new ToolStripMenuItem("复制(&C)"),
                new ToolStripMenuItem("粘贴(&V)"),
                new ToolStripMenuItem("全选(&A)")
            });

            // 工具菜单
            ToolStripMenuItem toolsMenu = new ToolStripMenuItem("工具(&T)");
                    toolsMenu.DropDownItems.AddRange(new[] {
                new ToolStripMenuItem("文件传输(&F)"),
                new ToolStripMenuItem("端口转发(&P)")
            });

            menuStrip.Items.AddRange(new[] { fileMenu, editMenu, toolsMenu });
            this.Controls.Add(menuStrip);
            this.MainMenuStrip = menuStrip;
        }


        private void CreateToolbar()
        {
            toolStrip = new ToolStrip { Dock = DockStyle.Top };

            toolStrip.Items.AddRange(new ToolStripButton[] {
                new ToolStripButton("新建会话") {
                    ToolTipText = "创建新会话"
                },
                new ToolStripButton("连接") {
                    ToolTipText = "连接选中的会话"
                },
                new ToolStripButton("断开") {
                    ToolTipText = "断开当前连接"
                },
                new ToolStripButton("文件传输") {
                    ToolTipText = "打开SFTP文件传输"
                },
                new ToolStripButton("终端") {
                    ToolTipText = "新建终端标签页"
                }
            });

            this.Controls.Add(toolStrip);
        }


        private void CreateStatusBar()
        {
            statusStrip = new StatusStrip();

            ToolStripStatusLabel statusLabel = new ToolStripStatusLabel
            {
                Text = "就绪",
                Spring = true
            };

            ToolStripStatusLabel connectionLabel = new ToolStripStatusLabel
            {
                Text = "未连接",
                BorderSides = ToolStripStatusLabelBorderSides.Left
            };

            statusStrip.Items.AddRange(new[] { statusLabel, connectionLabel });
            this.Controls.Add(statusStrip);
        }
    }
}
